<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   lianlianzan
 * @Last Modified time: 2022-03-27 16:52:39
 * 授权管理控制器
 */

namespace app\admin\logic;

class MerchantAuth extends AdminLogic {

	function initialize() {
		parent::initialize();
		
		$this->authRuleModel  = model('admin/AuthRule');
		$this->authGroupModel = model('admin/AuthGroup');
		$this->userModel      = model('admin/AdminUser');

	}
	
	/**
	 * 获取侧边栏菜单
	 * @param    string                    $position [description]
	 * @return   [type]                              [description]
	 * @Author   lianlianzan(13040@qq.com)
	 * @DateTime 2020-11-07
	 */
	public function getAdminSidebarMenu($roleid) {
		//根据组别获取菜单的树
		$merchantRuleDao = model('admin/MerchantRule');
		list($sidebarMenuTree, $selfMenuRule) = $merchantRuleDao->getNewMenuTree($roleid);
		//echo '菜单树:';print_r($sidebarMenuTree);
		//echo '父级菜单';print_r($selfMenuRule);exit;
		return array($sidebarMenuTree);
	}

	/**
	 * 检测规则权限
	 */
	public function checkAuth($roleid) {
		$module = MODULE_NAME; //模块名(项目名)
		$controller = CONTROLLER_NAME;
		if ($module == 'merchant_manage' && $controller == 'Index') {
			return array(1);
		}
		$module = strtolower($module);
		$controller = strtolower($controller);
		//echo 'module:'.$module;echo '<br>controller:'.$controller;exit;
		//print_r($subsidiaryArr);exit;
		$merchantAccessDao = model('admin/MerchantAccess');

		if (1) {
			$data = array(
				'roleid' 	=> $roleid,
				'm'			=> $module,
				'c'			=> $controller,
			);
			$count = $merchantAccessDao->where($data)->count();
			//echo 'getLastSql:';echo $authAccessDao->getLastSql();
			if ($count > 0) {
				return array($count);
			}
		}
	 }
}